package com.ruoyi.vstac.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.vstac.domain.EntryScore;
import com.ruoyi.vstac.mapper.EntryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.vstac.mapper.ScoreMapper;
import com.ruoyi.vstac.domain.Score;
import com.ruoyi.vstac.service.IScoreService;

import javax.annotation.Resource;

/**
 * 评分Service业务层处理
 * 
 * @author kingner
 * @date 2024-07-08
 */
@Service
public class ScoreServiceImpl implements IScoreService 
{
    @Resource
    private ScoreMapper scoreMapper;
    @Resource
    private EntryMapper entryMapper;

    /**
     * 查询评分
     * 
     * @param scoreId 评分主键
     * @return 评分
     */
    @Override
    public Score selectScoreByScoreId(int scoreId)
    {
        return scoreMapper.selectScoreByScoreId(scoreId);
    }

    /**
     * 查询评分列表
     * 
     * @param score 评分
     * @return 评分
     */
    @Override
    public List<Score> selectScoreList(Score score)
    {
        return scoreMapper.selectScoreList(score);
    }

    @Override
    public List<EntryScore> selectEntryScoreList(EntryScore entryScore) {
        return scoreMapper.selectEntryScoreList(entryScore);
    }

    /**
     * 新增评分
     * 
     * @param score 评分
     * @return 结果
     */
    @Override
    public int insertScore(Score score)
    {
        //检查分数是否异常
        if(score.getTotalScore() > 100 && score.getTotalScore() != score.getJaScore()
            +score.getJcsmScore() +score.getJxbgScore() +score.getKcbzScore()+score.getPyfaScore()+score.getVideoScore()) {
            throw new RuntimeException("分数异常");
        }
        //上传分数
        scoreMapper.insertScore(score);

        // 修改作品评审状态
        score.setCreateTime(DateUtils.getNowDate());
        return 1;
    }

    /**
     * 修改评分
     * 
     * @param score 评分
     * @return 结果
     */
    @Override
    public int updateScore(Score score)
    {
        //  检查分数是否异常
        if(score.getTotalScore() > 100 && score.getTotalScore() != score.getJaScore()
                +score.getJcsmScore() +score.getJxbgScore() +score.getKcbzScore()+score.getPyfaScore()+score.getVideoScore()) {
            throw new RuntimeException("分数异常");
        }

        return scoreMapper.updateScore(score);
    }

    /**
     * 批量删除评分
     * 
     * @param scoreIds 需要删除的评分主键
     * @return 结果
     */
    @Override
    public int deleteScoreByScoreIds(int[] scoreIds)
    {
        String stattus = "0";
        for (int scoreId : scoreIds) {
            entryMapper.setStatus(stattus,scoreId);
            scoreMapper.deleteScoreByScoreIds(scoreIds);
        }
        return 1;
    }

    /**
     * 删除评分信息
     * 
     * @param scoreId 评分主键
     * @return 结果
     */
    @Override
    public int deleteScoreByScoreId(int scoreId)
    {
        return scoreMapper.deleteScoreByScoreId(scoreId);
    }
}
